//
//  ZCAddNewAddressInputCell.m
//  ZCJZ
//
//  Created by sujeking on 2019/2/27.
//  Copyright © 2019年 jeking. All rights reserved.
//

#import "ZCAddNewAddressInputCell.h"
#import <BlocksKit+UIKit.h>
@interface ZCAddNewAddressInputCell()
@property (weak, nonatomic) IBOutlet UILabel *label;
@property (weak, nonatomic) IBOutlet UITextField *inputTF;
@end

@implementation ZCAddNewAddressInputCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.inputTF.delegate = self;
    [self.inputTF bk_addEventHandler:^(id sender) {
        if (self.length != 0) {
            if (self.inputTF.text.length >= self.length) {
                self.inputTF.text = [self.inputTF.text substringToIndex:self.length];
            }
        }
    } forControlEvents:UIControlEventEditingChanged];

    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

- (void)setKeystr:(NSString *)keystr {
    _keystr = keystr;
    self.label.text = keystr;
}

- (void)setValuestr:(NSString *)valuestr {
    _valuestr = valuestr;
    self.inputTF.text = valuestr;
}

- (void)setPlaceholdstr:(NSString *)placeholdstr {
    _placeholdstr = placeholdstr;
    self.inputTF.placeholder = placeholdstr;
}

- (void)setKeyboardType:(UIKeyboardType)keyboardType {
    _keyboardType = keyboardType;
    self.inputTF.keyboardType = keyboardType;
}

- (void)textFieldDidEndEditing:(UITextField *)textField {
    [self.delegate addNewAddressInputCellInputAction:self.indexPath content:textField.text];
}

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    if (self.type == ZCAddNewAddressInputCellType_Select) {
        [[UIApplication sharedApplication].keyWindow endEditing:YES];
        [self.delegate addNewAddressInputCellSelectAction:self.indexPath];
        return NO;
    } else {
//        UIButton *clsBtn = [self.inputTF valueForKey:@"_clearButton"];
//        if (clsBtn.currentImage != nil) {
//            UIImage *im = [clsBtn.currentImage imageWithColor:UIColorFromRGB(0xcccccc)];
//            [clsBtn setImage:im forState:UIControlStateNormal];
//            self.lineView.backgroundColor = UIColorFromRGB(0xF8F8FC);
//        }
        return YES;
    }
}

- (void)setUserInteractionEnabled:(BOOL)userInteractionEnabled {
    [super setUserInteractionEnabled:userInteractionEnabled];
    self.inputTF.userInteractionEnabled = userInteractionEnabled;
}

- (void)setSecureTextEntry:(BOOL)secureTextEntry {
    _secureTextEntry = secureTextEntry;
    self.inputTF.secureTextEntry = secureTextEntry;
}

@end
